public class QueueTest {
    public static void main(String[] args) {
        Queue queue = new Queue();
        queue.dequeue();
        queue.enqueue(1);
        queue.enqueue(2);
        queue.enqueue(3);
        queue.dequeue();
        queue.dequeue();
        queue.dequeue();
        queue.dequeue();
    }
}

class Node1 {
    int data;
    Node1 next;

    public Node1(int data, Node1 next) {
        this.data = data;
        this.next = next;
    }

    public int getData() {
        return data;
    }

    public void setData(int data) {
        this.data = data;
    }

    public Node1 getNext() {
        return next;
    }

    public void setNext(Node1 next) {
        this.next = next;
    }

    @Override
    public String toString() {
        return "Node1{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }
}

class Queue {
    Node1 front;
    Node1 rear;

    public Queue() {
        front = rear = null;
    }

    public void enqueue(int data) {
        Node1 newNode = new Node1(data, null);
        if (front == null) {
            front = rear = newNode;  // 当队列为空时，front 和 rear 都指向新节点
        } else {
            rear.next = newNode; // 将新节点添加到队列尾部
            rear = newNode; // 更新 rear 指针
        }
        System.out.println("enqueued data: " + data);
    }

    public void dequeue() {
        if (front == null) {
            System.out.println("front is null");
        } else {
            Node1 temp = front;
            if (front.next == null) {
                rear = null;        // 如果队列中只有一个元素，dequeue 后 rear 也应该为 null
            }
            front = front.next;
            System.out.println("dequeued data: " + temp.data);
        }
    }
}
